<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>04-函数式组件props</title>
  </head>
  <body>
    <div id="app"></div>

    <!-- 导入 react 主库 -->
    <script src="../js/react.development.js"></script>
    <!-- 导入 reactDom 扩展库 -->
    <script src="../js/react-dom.development.js"></script>
    <!-- 导入 babel 用于将jsx转为js -->
    <script src="../js/babel.min.js"></script>
    <!-- 导入 prop-types 用于对组件标签属性进行限制 -->
    <script src="../js//prop-types.js"></script>

    <script type="text/babel">
      function Person(props) {
        const {name, age, sex} = props
        return (
          <ul>
            <li>名字：{name}</li>
            <li>年龄：{age}</li>
            <li>性别：{sex}</li>
          </ul>
        );
      }

      Person.propTypes = {
        name: PropTypes.string.isRequired, // 限制name为string类型并且必传
        sex: PropTypes.string,
        age: PropTypes.number,
      };

      Person.defaultProps = {
        sex: "男女",
      };

      // 渲染虚拟DOM
      const p = { name: "st", age: 18, sex: "男" };
      ReactDOM.render(<Person {...p} />, document.getElementById("app"));
    </script>
  </body>
</html>
